using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace OpenWaves.ActivityFeed
{
    [DataContract]
    public class Subscriber
    {
        public Subscriber()
        {
            this.Subscriptions = Enumerable.Empty<Topic>();
        }

        public Subscriber(string subscriberId) : this()
        {
            this.Id = subscriberId;
        }

        [DataMember]
        public string Id { get; private set; }

        [DataMember]
        public IEnumerable<Topic> Subscriptions { get; private set; }

        public void SubscribeToTopics(IEnumerable<Topic> topics)
        {
            this.Subscriptions = this.Subscriptions.Union(topics).ToList();
        }

        public void UnsubscribeFromTopics(IEnumerable<Topic> topics)
        {
            this.Subscriptions = this.Subscriptions.Except(topics).ToList();
        }
    }
}